package loads

import (
	"jvm/nzpJvm/instructions/base"
	"jvm/nzpJvm/runtime_area"
)

// 将局部变量表指定位置的float类型变量压入操作数栈
type FLOAD struct{ base.Index8Instruction }
type FLOAD_0 struct{ base.NoOperandsInstruction }
type FLOAD_1 struct{ base.NoOperandsInstruction }
type FLOAD_2 struct{ base.NoOperandsInstruction }
type FLOAD_3 struct{ base.NoOperandsInstruction }

func (self *FLOAD) Execute(frame *runtime_area.Frame) {
	_fload(frame, self.Index)
}

func (self *FLOAD_0) Execute(frame *runtime_area.Frame) {
	_fload(frame, 0)
}

func (self *FLOAD_1) Execute(frame *runtime_area.Frame) {
	_fload(frame, 1)
}

func (self *FLOAD_2) Execute(frame *runtime_area.Frame) {
	_fload(frame, 2)
}

func (self *FLOAD_3) Execute(frame *runtime_area.Frame) {
	_fload(frame, 3)
}

func _fload(frame *runtime_area.Frame, index uint) {
	// 从栈帧的局部变量表中指定位置取出一个float值，
	val := frame.LocalVars().GetFloat(index)
	// 将其压到操作数栈中
	frame.OperandStack().PushFloat(val)
}
